//
//  SubmitOrderContactInfoView.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/28.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "SubmitOrderContactInfoView.h"

@interface SubmitOrderContactInfoView ()<UITextFieldDelegate>

@end

@implementation SubmitOrderContactInfoView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.nameTF.delegate = self;
    self.phoneTF.delegate = self;
    
    self.nameTF.tag = 100;
    self.phoneTF.tag = 200;
    
    [self.serTimeControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.SubmitOrderContactInfoBlock) {
            self.SubmitOrderContactInfoBlock(@"",SubmitOrderContactInfoType_sertime);
        }
    }];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.nameControl pp_clipCorners:UIRectCornerTopLeft|UIRectCornerTopRight radius:6];
        [self.serTimeControl pp_clipCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight radius:6];
    });
}


- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    SubmitOrderContactInfoType type;
    switch (textField.tag) {
        case 100:{
            type = SubmitOrderContactInfoType_name;
        } break;
        case 200:{
            type = SubmitOrderContactInfoType_phone;
        } break;
        default:{
            type = SubmitOrderContactInfoType_name;
        } break;
    }
    
    if (self.SubmitOrderContactInfoBlock) {
        self.SubmitOrderContactInfoBlock(textField.text, type);
    }
}

@end
